package com.mycompany.myapp.web.rest.controller;

import com.mycompany.myapp.service.CollectionService;
import com.mycompany.myapp.service.dto.CollectionDTO;
import com.mycompany.myapp.web.rest.utils.ResultObj;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.net.URISyntaxException;
import java.util.List;

@Api(tags = {"收藏管理"})
@RestController
@RequestMapping("/api")
public class CollectionController {

    private final CollectionService collectionService;

    public CollectionController(CollectionService collectionService) {
        this.collectionService = collectionService;
    }

    @ApiOperation("添加收藏 RequestBody")
    @PostMapping("/collection/add")
    public ResultObj createCollection(@RequestBody CollectionDTO collectionDTO){
        return collectionService.createCollection(collectionDTO);
    }

    @ApiOperation("根据用户id查询收藏")
    @PostMapping("/collection/userid")
    public ResultObj findByuserId(Long userId)throws URISyntaxException {
        return ResultObj.backInfo(true,200,"获取成功!",collectionService.findByUserId(userId));
    }

    @ApiOperation("根据id批量删除收藏")
    @DeleteMapping("/collection/id")
    public ResultObj deleteCollections(@RequestParam List<Long> collectionids){
        return collectionService.deleteCollections(collectionids);
    }

}
